<?php
class content extends Model{
	public $list_pages;
    
    public function __construct() {
        parent::__construct();
    }
    
    public function op_list($where = '', $orderby = '', $page = 0, $page_size = 10, $url = '') {
		$where = ' WHERE id > 0 '.$where;
		$orderby = ' ORDER BY '. $orderby .' id DESC ';
		
		$page = max(intval($page), 1);
		$limit = intval($page) ? ' LIMIT '.(($page-1)*$page_size) . ','. $page_size : '';
		
        $sql = 'SELECT * FROM '. $this->db_config['db_prefix'] .'content'. $where . $orderby . $limit;
        $rows = $this->db->getRows($sql);
		
		$c_sql = 'SELECT count(*) as c FROM '. $this->db_config['db_prefix'].'content'. $where ;
		$c_row = $this->db->getOne($c_sql);
		$count = $c_row['c'];
		$this->list_pages = $this->pages->getPages($count, $page_size, $page, $url);
		
        return $rows;
    }
    
    public function op_insert($field_values) {
        $field_values = array('title'=>'测试数据-标题', 'content'=>'测试数据-内容');
        $this->db->execute('INSERT', 'content', $field_values);
    }
    
    public function op_update($id, $field_values) {
        if (!$id) return false;
        $field_values = array('title'=>'测试数据-标题', 'content'=>'测试数据-内容');
        $this->db->execute('UPDATE', 'content', $field_values, ' WHERE id = '.$id);
    }
    
    public function op_delete($id) {
        if (!$id) return false;
        $this->db->execute('DELETE', 'content', '', ' WHERE id = '.$id); 
    }
}
?>
